﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PropertyManagement {
    public static class FormHelper {
        private readonly  static Dictionary<IntPtr, string> oldFormText = new Dictionary<IntPtr, string>();

        public static void ShowErrorMsg(string p) {
            MessageBox.Show(p, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public static void ShowInfoMsg(string p) {
            MessageBox.Show(p, "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
      

        public static void Loading(this Form form, string msg,object sender) {
            oldFormText.Add(form.Handle,form.Text);
            form.Text = msg;
            form.Cursor = Cursors.WaitCursor;
            if (sender!=null && sender is Control) {
                ((Control) sender).Enabled = false;
            }
        }

        public static void Loaded(this Form form, object sender) {
            if (oldFormText.ContainsKey(form.Handle)) {
                form.Text = oldFormText[form.Handle];
                oldFormText.Remove(form.Handle);
            }
          
            form.Cursor = Cursors.Arrow;
            if (sender!=null && sender is Control) {
                ((Control)sender).Enabled = true;
            }
        }


    }
}
